<?php
/**
 * 情报
 */

namespace app\sports\match\service;

class IntelligenceService
{
    /**
     * 根据比赛ID获取情报
     *
     * @param boolean isHome 是否主队 true是
     */
    public function getIntelligenceByMatchId($matchId, $isHome = true)
    {
        //获取比赛信息
        $battleService = new BattleService();
        $commonInfo = $battleService->getBattleInfo($matchId);

        $matchModel = new \app\sports\match\model\MatchModel();
        $data = $matchModel->getIntelligenceByMatchId($matchId);
        if (empty($data)) {
            return [];
        }

        $info = $data['info'];
        $chance = $data['chance'];

        $info = json_decode($info, true);

        $good = isset($info['good']) ? $info['good'] : [];
        $bad = isset($info['bad']) ? $info['bad'] : [];
        $neutral = isset($info['neutral']) ? $info['neutral'] : [];

        //主队
        if ($isHome) {
            $goodInfo = isset($good['home']) ? $good['home'] : [];
            $badInfo = isset($bad['home']) ? $bad['home'] : [];
            $neutralInfo = isset($neutral['home']) ? $neutral['home'] : [];
        } else {
            $goodInfo = isset($good['away']) ? $good['away'] : [];
            $badInfo = isset($bad['away']) ? $bad['away'] : [];
            $neutralInfo = isset($neutral['away']) ? $neutral['away'] : [];
        }

        return [
            'match_common' => $commonInfo,
            'good' => $goodInfo,
            'bad' => $badInfo,
            'neutral' => $neutralInfo
        ];
    }
}